#include "myhead.h"
#include "def.h"
int parseCommand(char* buf, char* params[], int* paramNumber)
{
	int i;
	*paramNumber=0;
	if ((params[*paramNumber]=strtok(buf, delim))!=NULL)
	{
		for (i=CommandNumber-1; i>=0; i--)
		{
			if (strcmp(params[*paramNumber], commandStr[i])==0)
			{
				break;	
			}
		}
		//when not found, i==-1
		if (i==-1)
		{
			return i;
		}
	}
	else
	{
		return -1;
	}	
	(*paramNumber)++;
	//the maximum param number is only 2, so I test for 3 to see if strtok return NULL
	while (1)
	{
		if ((params[*paramNumber]=strtok(NULL, delim))==NULL)
		{
			break;
		}
		(*paramNumber)++;
		if (*paramNumber==4)
		{
			//this means the param number is more than 2 and it is wrong
			return -1;
		}
	}
	return i;
}
